<?xml version="1.0" encoding="utf-8" ?>
<!--
    Copyright (c) 2007 Natan Vivo
    DBLGen <http://dblgen.sourceforge.net>

    DBLGen is free software: you can redistribute it and/or modify it
    under the terms of the GNU General Public License version 3 as
    published by the Free Software Foundation.

    DBLGen is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program. If not, see <http://www.gnu.org/licenses/>.
-->
<xsd:schema id="DBLGen"
           targetNamespace="http://dblgen/project"
           xmlns:dbl="http://dblgen/project"
           xmlns:xsd="http://www.w3.org/2001/XMLSchema">

	<xsd:element name="project">
		<xsd:complexType>
			<xsd:all>
				<xsd:element name="plugins" minOccurs="0">
					<xsd:complexType>
						<xsd:all>
							<xsd:element name="importPlugin" type="dbl:PluginType" minOccurs="0" />
							<xsd:element name="exportPlugin" type="dbl:PluginType" minOccurs="0" />
						</xsd:all>
					</xsd:complexType>
				</xsd:element>
				<xsd:element name="tables" minOccurs="0">
					<xsd:complexType>
						<xsd:sequence>
							<xsd:element name="table" type="dbl:TableType" minOccurs="0" maxOccurs="unbounded" />
						</xsd:sequence>
					</xsd:complexType>
				</xsd:element>
				<xsd:element name="settingGroups" minOccurs="0">
					<xsd:complexType>
						<xsd:sequence>
							<xsd:element name="settingGroup" minOccurs="0" maxOccurs="unbounded">
								<xsd:complexType>
									<xsd:sequence>
										<xsd:element name="setting" minOccurs="0" maxOccurs="unbounded">
											<xsd:complexType mixed="true">
												<xsd:attribute name="name" />
											</xsd:complexType>
										</xsd:element>
									</xsd:sequence>
									<xsd:attribute name="type" type="xsd:string" />
									<xsd:attribute name="key" type="xsd:string" use="optional" />
								</xsd:complexType>
							</xsd:element>
						</xsd:sequence>
					</xsd:complexType>
				</xsd:element>
			</xsd:all>
		</xsd:complexType>
	</xsd:element>

	<xsd:complexType name="PluginType">
		<xsd:attribute name="type" use="required">
			<xsd:simpleType>
				<xsd:restriction base="xsd:normalizedString">
					<xsd:minLength value="3" />
				</xsd:restriction>
			</xsd:simpleType>
		</xsd:attribute>
	</xsd:complexType>

	<xsd:complexType name="TableType">
		<xsd:all>
			<xsd:element name="comments" minOccurs="0" />
			<xsd:element name="columns" minOccurs="0">
				<xsd:complexType>
					<xsd:sequence>
						<xsd:element name="column" type="dbl:ColumnType" minOccurs="0" maxOccurs="unbounded" />
					</xsd:sequence>
				</xsd:complexType>
			</xsd:element>
			<xsd:element name="methods" minOccurs="0">
				<xsd:complexType>
					<xsd:sequence>
						<xsd:element name="method" type="dbl:MethodType" minOccurs="0" maxOccurs="unbounded" />
					</xsd:sequence>
				</xsd:complexType>
			</xsd:element>
			<xsd:element name="customAttributes" type="dbl:CustomAttributeType" minOccurs="0" />
			<xsd:element name="exportSettings" minOccurs="0" />
		</xsd:all>
		<xsd:attribute name="name" type="xsd:string" use="required" />
		<xsd:attribute name="uniqueid" type="xsd:string" />
		<xsd:attribute name="alias" type="xsd:string" />
		<xsd:attribute name="schema" type="xsd:string" />
		<xsd:attribute name="sourceType">
			<xsd:simpleType>
				<xsd:restriction base="xsd:string">
					<xsd:enumeration value="Table" />
					<xsd:enumeration value="View" />
					<xsd:enumeration value="Custom" />
				</xsd:restriction>
			</xsd:simpleType>
		</xsd:attribute>
		<xsd:attribute name="canExport" type="xsd:boolean" default="1" />
	</xsd:complexType>
	
	<xsd:complexType name ="MethodType">
		<xsd:all>
			<xsd:element name="comments" type="xsd:string" minOccurs="0" />
			<xsd:element name="QueryRow" type="dbl:Methods" minOccurs="0" />
		</xsd:all>
		<xsd:attribute name="name" type="xsd:string" use="required" />
		<xsd:attribute name="sqlQuery" type="xsd:string" />
	</xsd:complexType>

	<xsd:complexType name="Methods">
		<xsd:sequence>
			<xsd:element name="CustomAttributeQueryType" type="dbl:CustomAttributeQueryType" minOccurs="0" maxOccurs="unbounded" />
		</xsd:sequence>
	</xsd:complexType>

	<xsd:complexType name="CustomAttributeQueryType">
		<xsd:attribute name="order" type="xsd:int"/>
		<xsd:attribute name="fieldName" type="xsd:string"/>
		<xsd:attribute name="conjunction" type="xsd:string"/>
		<xsd:attribute name="parameterName" type="xsd:string"/>
		<xsd:attribute name="defaultValue" type="xsd:string"/>
		<xsd:attribute name="operation" type="xsd:string"/>
	</xsd:complexType>

	<xsd:complexType name="ColumnType">
		<xsd:all>
			<xsd:element name="comments" minOccurs="0" />
			<xsd:element name="customAttributes" type="dbl:CustomAttributeType" minOccurs="0" />
		</xsd:all>
		<xsd:attribute name="name" type="xsd:string" use="required" />
		<xsd:attribute name="description" type="xsd:string" />
		<xsd:attribute name="sqlType" type="xsd:string" />
		<xsd:attribute name="length" type="xsd:nonNegativeInteger" />
		<xsd:attribute name="octetLength" type="xsd:nonNegativeInteger" />
		<xsd:attribute name="precision" type="xsd:nonNegativeInteger" />
		<xsd:attribute name="scale" type="xsd:nonNegativeInteger" />
		<xsd:attribute name="isNullable" type="xsd:boolean" default="0" />
		<xsd:attribute name="isComputed" type="xsd:boolean" default="0" />
		<xsd:attribute name="isPrimaryKey" type="xsd:boolean" default="0" />
		<xsd:attribute name="isForeignKey" type="xsd:boolean" default="0" />
		<xsd:attribute name="referencedSchema" type="xsd:string" />
		<xsd:attribute name="referencedTable" type="xsd:string" />
		<xsd:attribute name="referencedColumn" type="xsd:string" />
		<xsd:attribute name="alias" type="xsd:string" />
		<xsd:attribute name="type" type="xsd:string" />
		<xsd:attribute name="isReadOnly" type="xsd:boolean" default="0" />
		<xsd:attribute name="canExport" type="xsd:boolean" default="1" />
	</xsd:complexType>

	<xsd:complexType name="CustomAttributeType">
		<xsd:sequence>
			<xsd:element name="attribute" minOccurs="0" maxOccurs="unbounded">
				<xsd:complexType mixed="1">
					<xsd:attribute name="name" type="xsd:string" use="required" />
				</xsd:complexType>
			</xsd:element>
		</xsd:sequence>
	</xsd:complexType>

</xsd:schema>
